package com.mogu.comment.service.impl;

import com.mogu.comment.mapper.CommentListMapper;
import com.mogu.comment.mapper.CommentMapper;
import com.mogu.comment.pojo.CommentList;
import com.mogu.comment.service.CommentService;
import com.mogu.entity.TComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:不在能知，而在能行
 *
 * @author: 梁西华
 * @date: 2020/6/15/10:24
 **/
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;
    @Autowired
    CommentListMapper commentListMapper;

    /**
     * 判断是否为广告评论
     * @param comment
     * @return
     */
    @Override
    public boolean cacheInvalidation(TComment comment) {
        int count =this.commentMapper.cacheInvalidation(comment.getUserUid(),comment.getContent());
        System.out.println("count:"+count);
        int num = 3;
        if (count < num){
            return false;
        }
        return true;
    }

    /**
     * 增加评论
     * @param comment
     */
    @Override
    public void addComment(TComment comment) {

        this.commentMapper.insert(comment);
    }

    /**
     * 根据博客id查询所有评论
     * @param blogUid
     * @return
     */
    @Override
    public List<CommentList> findComment(String blogUid) {
        return this.commentListMapper.findListByBlogUid(blogUid);
    }
}
